<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.48">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #b71505}
span.s1 {color: #003aef}
span.s2 {font: 9.0px Monaco; color: #002bb2}
span.s3 {font: 9.0px Monaco}
span.s4 {color: #5075b4}
span.s5 {color: #002bb2}
span.s6 {color: #000000}
span.s7 {color: #0014bd}
span.s8 {color: #20710d}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><b>SOMAreaWr<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>Write data over an n-D area in a buffer</b></p>
<p class="p2"><br></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>SOMAreaWr.kr(bufnum, inputdata, coords, netsize, numdims, nhood, gate)</b></p>
<p class="p2"><br></p>
<p class="p3">If you are training a SOM using <a href="SOMTrain.html"><span class="s1">SOMTrain</span></a>, and you also want some data to be stored along with each node, generated during the training process, then you can simply use BufWr in combination with <span class="s2">SOMRd</span><span class="s3">.coordsToBufIndex</span>. However, this won't let you write the datum to a neighbourhood, just to a single node. Using <b>SOMAreaWr</b> you can write to a hypercubic area of your data storage buffer. You need to feed it <b>coords</b> for writing, which you'd typically get using <a href="SOMRd.html"><span class="s1">SOMRd</span></a>.</p>
<p class="p2"><br></p>
<p class="p3"><span class="Apple-converted-space"> </span>- <b>bufnum</b><span class="Apple-tab-span">	</span>- A reference to a <a href="SC://Buffer"><span class="s1">Buffer</span></a> where the data will be written (<i>NOT</i> the SOM buffer).</p>
<p class="p3"><span class="Apple-converted-space"> </span>- <b>inputdata</b><span class="Apple-tab-span">	</span>- An <a href="SC://Array"><span class="s4">Array</span></a> of the input signals to be stored.</p>
<p class="p3"><span class="Apple-converted-space"> </span>- <b>netsize</b><span class="Apple-tab-span">	</span>- The size of the neural net along one dimension.</p>
<p class="p3"><span class="Apple-converted-space"> </span>- <b>numdims</b> - The dimensionality of the neural net. Choose from 1, 2, 3, or 4.</p>
<p class="p3"><span class="Apple-converted-space"> </span>- <b>nhood</b><span class="Apple-tab-span">	</span>- The size of the neighbourhood you want to write to, a modulateable value between 0 and 1. Zero means write to just one location. One means definitely write to all locations.</p>
<p class="p3"><span class="Apple-converted-space"> </span>- <b>gate</b> <span class="Apple-tab-span">	</span>-<span class="Apple-converted-space">  </span>A simple on-or-off control. When off (gate&lt;=0) the incoming data is ignored.</p>
<p class="p2"><br></p>
<p class="p3">The buffer must be of the right size to hold the data you're interested in, namely</p>
<p class="p2"><br></p>
<p class="p3"><span class="Apple-tab-span">	</span>b = <span class="s5">Buffer</span>.alloc(s, netsize**numdims, inputdata.size);</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p3"><b>TESTING:</b></p>
<p class="p3">Let's create a zero'ed Buffer representing 2D data in just one channel, then run SOMAreaWr very briefly, then plot the results to see that the correct value has been written over the correct expanse.</p>
<p class="p2"><br></p>
<p class="p3">s.boot;</p>
<p class="p3">~netsize = 20;</p>
<p class="p4"><span class="s6">~numdatadims = 3; </span>// We only "really" use 1 dim in this visualisation, but we write the data to all dims</p>
<p class="p3">b = <span class="s7">Buffer</span>.alloc(s, ~netsize**2, ~numdatadims);</p>
<p class="p4">// You only need to run these for a second:</p>
<p class="p3">x = {<span class="s7">SOMAreaWr</span>.kr(b, [-0.33333333].dup(~numdatadims), [10, 10], ~netsize, 2, 1)}.play;</p>
<p class="p3">x.free;</p>
<p class="p3">x = {<span class="s7">SOMAreaWr</span>.kr(b, [-0.15].dup(~numdatadims), [2, 18], ~netsize, 2, 0)}.play;</p>
<p class="p3">x.free;</p>
<p class="p3">x = {<span class="s7">SOMAreaWr</span>.kr(b, [0.5].dup(~numdatadims), [6, 6], ~netsize, 2, 0.1)}.play;</p>
<p class="p3">x.free;</p>
<p class="p3">x = {<span class="s7">SOMAreaWr</span>.kr(b, [1.0].dup(~numdatadims), [14, 10], ~netsize, 2, 0.2)}.play;</p>
<p class="p3">x.free;</p>
<p class="p4">// Now the heatmap should show us some neat squares:</p>
<p class="p3">b.loadToFloatArray(action: {<span class="s7">|arr|</span> {arr.clump(~numdatadims).flop.choose.clump(~netsize).flop.heatMap(colscheme:<span class="s8">\coals</span>)}.defer});</p>
<p class="p2"><br></p>
<p class="p4">// This generates more intricate data (rerun the heatmap line above to see the result):</p>
<p class="p3">(</p>
<p class="p3">x = {</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="s7">var</span> location = {<span class="s7">LFNoise1</span>.kr(50).range(0, ~netsize-1)}.dup(2);</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="s7">var</span> size = <span class="s7">XLine</span>.kr(1, 0.000000001, 1, doneAction: 2);</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="s7">var</span> value = <span class="s7">Line</span>.kr(0, 9<span class="Apple-converted-space">                      </span>, 1, doneAction: 2).dup(~numdatadims);</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="s7">SOMAreaWr</span>.kr(b, value, location, ~netsize, 2, size);</p>
<p class="p3">}.play;</p>
<p class="p3">)</p>
</body>
</html>
